# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=pygobject
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-gobject"
         "${MINGW_PACKAGE_PREFIX}-python3-gobject"
         "${MINGW_PACKAGE_PREFIX}-pygobject-devel")
pkgver=3.28.2
pkgrel=1
pkgdesc="Python Bindings for GLib/GObject/GIO/GTK+ (mingw-w64)"
arch=(any)
url="https://pygobject.readthedocs.io"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-python3-cairo"
             "${MINGW_PACKAGE_PREFIX}-python2-cairo")
source=(https://download.gnome.org/sources/pygobject/${pkgver%.*}/${_realname}-${pkgver}.tar.xz)
sha256sums=('ac443afd14fcb9ff5744b65d6e2b380e70510278404fb8684a9b9fb089e6f2ca')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
}

build() {
  cd "${srcdir}"

  rm -rf python{2,3}-build devel || true
  mkdir devel

  for builddir in python{2,3}-build; do
    cp -r ${_realname}-${pkgver} ${builddir}
    pushd ${builddir}
    ${MINGW_PREFIX}/bin/${builddir%-build} setup.py build
    popd
  done
}

package_python2-gobject() {
  pkgdesc="Python 2 bindings for GLib/GObject/GIO/GTK+ (mingw-w64)"
  depends=("${MINGW_PACKAGE_PREFIX}-glib2"
           "${MINGW_PACKAGE_PREFIX}-python2-cairo"
           "${MINGW_PACKAGE_PREFIX}-libffi"
           "${MINGW_PACKAGE_PREFIX}-gobject-introspection-runtime"
           "${MINGW_PACKAGE_PREFIX}-pygobject-devel=${pkgver}")

  cd python2-build
  # --no-compile because older packages didn't install .pyc and adding them
  # would lead to upgrade conflicts
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --no-compile
  mv "${pkgdir}${MINGW_PREFIX}"/{include,lib/pkgconfig} "${srcdir}/devel"
}

package_python3-gobject() {
  pkgdesc="Python 3 bindings for GLib/GObject/GIO/GTK+ (mingw-w64)"
  depends=("${MINGW_PACKAGE_PREFIX}-glib2"
           "${MINGW_PACKAGE_PREFIX}-python3-cairo"
           "${MINGW_PACKAGE_PREFIX}-libffi"
           "${MINGW_PACKAGE_PREFIX}-gobject-introspection-runtime"
           "${MINGW_PACKAGE_PREFIX}-pygobject-devel=${pkgver}")

  cd python3-build
  # --no-compile because older packages didn't install .pyc and adding them
  # would lead to upgrade conflicts
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --no-compile
  rm -r "${pkgdir}${MINGW_PREFIX}"/{include,lib/pkgconfig}
}

package_pygobject-devel() {
  pkgdesc="Development files for the pygobject bindings"

  cd "devel"
  mkdir -p "${pkgdir}${MINGW_PREFIX}"/{include,lib}
  mv include "${pkgdir}${MINGW_PREFIX}/"
  mv pkgconfig "${pkgdir}${MINGW_PREFIX}/lib/"
}

package_mingw-w64-i686-pygobject-devel() {
  package_pygobject-devel
}

package_mingw-w64-x86_64-pygobject-devel() {
  package_pygobject-devel
}

package_mingw-w64-i686-python2-gobject() {
  package_python2-gobject
}

package_mingw-w64-i686-python3-gobject() {
  package_python3-gobject
}

package_mingw-w64-x86_64-python2-gobject() {
  package_python2-gobject
}

package_mingw-w64-x86_64-python3-gobject() {
  package_python3-gobject
}
